package com.dekaru.math.type;

import  java.io.*;


/**
 * Homework 3 (The Class <code>Rational</code>)
 * <p> 
 * driver for the class {@link Rational}
 * </p>
 *
 * @author  Sean Bufano
 * @version  2.2.0
 * @see  Rational
 */
public class RationalDriver  {

	private final static PrintWriter  stdOut = new  PrintWriter(System.out, true);
	private final static PrintWriter  stdErr = new  PrintWriter(System.err, true);



	public static void  main(String[]  args)  {

		stdOut.println("Note that these tests assume toString is implemented correctly.  For example, for 1/2, toString must return \"1/2\" exactly.  Whitespace matters.");
		stdOut.println();
		stdOut.println();
		stdOut.print("Testing started...");
		stdOut.flush();

		if (!(new  Rational()).toString().equals("0/1"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in constructor Rational().  The call Rational() failed to create 0/1.");
			System.exit(1);
		}  
		if (!(new  Rational(-4)).toString().equals("-4/1"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in constructor Rational(int).  The call Rational(-4) failed to create -4/1.");
			System.exit(1);
		}
		if (!(new  Rational(-8, -16)).toString().equals("1/2"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in constructor Rational(int, int).  The call Rational(-8, -16) failed to create 1/2.");
			System.exit(1); 
		}
		if (!(new  Rational(8, -16)).toString().equals("-1/2"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in constructor Rational(int, int).  The call Rational(8, -16) failed to create -1/2.");
			System.exit(1);
		}
		if (!(new  Rational(8, 16)).toString().equals("1/2"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in constructor Rational(int, int).  The call Rational(8, 16) failed to create 1/2.");
			System.exit(1);
		}
		if (!(new  Rational(0, 5)).toString().equals("0/1"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in constructor Rational(int, int).  The call Rational(0, 5) failed to create 0/1.");
			System.exit(1);
		}
		if (!(new  Rational(new  Rational(-8, -16))).toString().equals("1/2"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in constructor Rational(Rational).  It was called to create a copy of Rational(-8/-16) but failed to create 1/2.");
			System.exit(1);
		}
		if ((new  Rational(1, 2)).getNumerator() != 1)  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in getNumerator.  It failed to retrieve the numerator from 1/2.");
			System.exit(1);
		}
		if ((new  Rational(1, 2)).getDenominator() != 2)  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in getDenominator.  It failed to retrieve the denominator from 1/2.");
			System.exit(1);
		}

		stdOut.println("caca!!");
		Rational  temp;
		temp = new  Rational(2, 3);
		
		temp.setNumerator(3);
		if (temp.getNumerator() != 1)  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in setNumerator.  Called to change the numerator in 2/3 to 3.  A subsequent call to getNumerator failed to return 1.");
			System.exit(1);
		}
		temp = new  Rational(2, 3);
		temp.setDenominator(2);
		if (temp.getDenominator() != 1)  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in setDenominator.  Called to change the denominator in 2/3 to 2.  A subsequent call to getDenominator failed to return 1.");
			System.exit(1);
		}

		if (!(new  Rational(-4, 5)).isNegative())  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in isNegative.  Failed to return true for -4/5.");
			System.exit(1);
		}
		if ((new  Rational(4, 5)).isNegative())  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in isNegative.  Failed to return false for 4/5.");
			System.exit(1);
		}
		if (!(new  Rational()).isZero())  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in isZero.  Failed to return true for 0/1.");
			System.exit(1);
		}
		if ((new  Rational(6)).isZero())  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in isZero.  Failed to return false for 6/1.");
			System.exit(1);
		}
		if ((new  Rational(-4, 5)).isPositive())  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in isPositive.  Failed to return false for -4/5.");
			System.exit(1);
		}
		if (!(new  Rational(4, 5)).isPositive())  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in isPositive.  Failed to return true for 4/5.");
			System.exit(1);
		}
		if (!(new  Rational(7, 8)).negation().toString().equals("-7/8"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in negation.  Failed to return -7/8 when negating 7/8.");
			System.exit(1);
		}
		if (!(new  Rational(-7, 8)).negation().toString().equals("7/8"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in reciprocal.  Failed to return 7/8 when negating -7/8.");
			System.exit(1);
		}
		if (!(new  Rational(7, 8)).reciprocal().toString().equals("8/7"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in reciprocal.  Failed to return 8/7 when inverting 7/8.");
			System.exit(1);
		}
		if (!(new  Rational(-7, 8)).reciprocal().toString().equals("-8/7"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in negation.  Failed to return -8/7 when inverting -7/8.");
			System.exit(1);
		}
		if (!(new  Rational(1, 3)).plus(new  Rational(2, 3)).toString().equals("1/1"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in plus.  Sum of 1/3 and 2/3 failed to return 1/1.");
			System.exit(1);
		}
		if (!(new  Rational(1, 3)).minus(new  Rational(2, 3)).toString().equals("-1/3"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in minus.  Difference of 1/3 and 2/3 failed to return -1/3.");
			System.exit(1);
		}
		if (!(new  Rational(1, 3)).times(new  Rational(2, 3)).toString().equals("2/9"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in times.  Product of 1/3 and 2/3 failed to return 2/9.");
			System.exit(1);
		}
		if (!(new  Rational(1, 3)).dividedBy(new  Rational(-2, 3)).toString().equals("-1/2"))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in dividedBy.  Division of 1/3 by -2/3 failed to return -1/2.");
			System.exit(1);
		}
		if (!(new  Rational(1, 3)).equals(new  Rational(1, 3)))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in equals.  Failed to equate 1/3 and 1/3.");
			System.exit(1);
		}
		if ((new  Rational(1, 3)).equals(new  Rational(3, 1)))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in equals.  Erroneously equated 1/3 and 3/1.");
			System.exit(1);
		}
		if ((new  Rational(1, 3)).equals(new  Rational(-1, 3)))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in equals.  Erroneously equated 1/3 and -1/3.");
			System.exit(1);
		}
		if ((new  Rational(1, 3)).equals(new  Rational(1, 2)))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in equals.  Erroneously equated 1/3 and 1/2.");
			System.exit(1);
		}
		if ((new  Rational(1, 3)).equals(new  Rational(2, 3)))  {
			stdOut.println();
			stdOut.println("***");
			stdErr.println("Error in equals.  Erroneously equated 1/3 and 2, 3.");
			System.exit(1);
		}

		stdOut.println("done.  All driver tests passed");
	}
}